﻿using System;
using System.Collections.Generic;
using System.Text;
using Model.Models;
using System.Linq;

namespace LogisticsDAL
{
    public class SqlOrderManage : IOrdersManage
    {
        private readonly LogisticsDBContext context;

        public SqlOrderManage(LogisticsDBContext context)
        {
            this.context = context;
        }

        public List<Order> GetAll()
        {
            return context.Orders.ToList();
        }

        public object GetOrders(string Oid, string cname, string card, int Otype, int Status, string receivetel, DateTime createdate, DateTime comitedate)
        {
            var list = from a in context.Orders
                       join b in context.Customers
                       on a.Cid equals b.Cid
                       join c in context.Orderdetails
                       on a.Oid equals c.Oid
                       join d in context.Goodsmes
                       on c.Gid equals d.Gid
                       where a.Oid.Contains(Oid) || b.Cname.Contains(cname) || b.Card.Contains(card) || a.Otype == Otype || a.Status == Status || a.Receivetel.Contains(receivetel) || a.Createdate == createdate || a.Comitedate == comitedate
                       select new { a.Oid, b.Cid, b.Cname, c.Gid, c.Counts, d.Gname, a.Status };
            return list;
        }
    }
}
